﻿package {
	import flash.display.BitmapData;
	import flash.display.Shape;
	import flash.utils.getTimer;
	import idv.cjcat.pyronova.nodes.CopyPixels;
	import idv.cjcat.pyronova.nodes.FillRect;
	import idv.cjcat.pyronova.nodes.Group;
	import idv.cjcat.pyronova.nodes.Node;
	import idv.cjcat.pyronova.utils.PyroMath;
	
	public class Main extends PyronovaExample {
		
		private var group:Group;
		
		public function Main():void {
			super("CopyPixels");
		}
		
		override protected function buildPreprocessor():Node {
			//clean buffer
			return new FillRect(view.bitmapData().rect, 0x00000000);
		}
		
		override protected function buildRoot():Node {
			group = new Group();
			group.position.set(160, 100);
			
			var count:int = 50;
			for (var i:int = 0; i < count; ++i) {
				var bmpd:BitmapData = new BitmapData(50, 50, true, 0x00000000);
				bmpd.fillRect(bmpd.rect, int(0xFFFFFFFF * Math.random()));
				
				var theta:Number = PyroMath.TWO_PI * i / count;
				var copyPixels:Node = new CopyPixels(bmpd);
				copyPixels.center.set(25, 25);
				copyPixels.position.set(70 * Math.cos(theta), 70 * Math.sin(theta));
				group.add(copyPixels);
			}
			
			return group;
		}
		
		override protected function mainLoop():void {
			var t:Number = 1 + 0.3 * Math.sin(getTimer() / 500);
			group.scale.set(t, t);
			group.rotation += 0.5;
		}
	}
}